其他
如何快、准、狠使用R语言完成单因素方差分析
> x <- c(40, 10, 35, 25, 20, 15, 35, 15, -5, 30, 25, 70, 65, 45, 50, 50, 20, 45, 55, 20, 15, 80, -10, 105, 75, 10, 60, 45, 60, 30, 60, 30, 100, 85, 20, 55, 45, 30, 77, 105,123,124,145,156,120)
> group<-c(rep(1,15),rep(2,15),rep(3,15)) ##分组
> gro<-as.factor(group) ##因子化
> d<-split(x,gro) ##分组
> sapply(d,shapiro.test) #分组检验正态性
> bartlett.test(x,gro) #分组检测方差齐性
Bartlett test of homogeneity of variances
data: x and gro
Bartlett's K-squared = 7.584, df = 2, p-value = 0.02255 #方差不齐> kruskal.test(x~gro) #方差不齐,故选择kruskal非参数检验
Kruskal-Wallis rank sum test
data: x by gro
Kruskal-Wallis chi-squared = 12.485, df = 2, p-value = 0.001945
加入临床科研讨论群,请加13738062354或者pj1989zzj为好友,注明加群,就会拉你进群了。